﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Wokr2;

namespace Work2
{
    /// <summary>
    /// 登录
    /// </summary>
    public partial class Login : Form
    {

        public static String txtLogin_Username;
        public Login()
        {
            InitializeComponent();
        }
        private void btt_Login_Click(object sender, EventArgs e)
        {
 
            txtLogin_Username = tB_Account_Username.Text;
            String password = tB_Account_Password.Text;

            if (txtLogin_Username == "" || password == "")
            {
                MessageBox.Show("请输入用户名和密码！");
                return;
            }

     
            string sqlcon = @"Data Source=LAPTOP-LER1MVBI\SQLEXPRESS;Initial Catalog=电子族谱系统;uid=sa;pwd=zxcvbnm123";
            String sqlcom = "select User_id ,User_pwd from Users where User_id='" + txtLogin_Username + "' and User_pwd='" + password + "'";
            SqlConnection con = new SqlConnection(sqlcon);
            SqlCommand com = new SqlCommand(sqlcom, con);
            con.Open();

            SqlDataReader reader = com.ExecuteReader();
            if (reader.Read())
            {

                MessageBox.Show("登录成功");
                FrmMain fr = new FrmMain();
                fr.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码错误，请重新输入！");
            }
            con.Close();

       
            foreach (Control item in this.Controls)
            {
                if (item is TextBox)
                {
                    item.Text = "";
                }
            }
        }

    
        private void lb_Regist_Click(object sender, EventArgs e)
        {
            Regist rigist = new Regist();
            rigist.Show();
        }

      
       

    
        

        private void tB_Account_Username_TextChanged(object sender, EventArgs e)
        {

        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void pctrB_Image_Click(object sender, EventArgs e)
        {

        }

        private void tB_Account_Password_TextChanged(object sender, EventArgs e)
        {

        }

        private void Label2_Click(object sender, EventArgs e)
        {

        }
    }
}
